package com.sayimo.maker.mall.orders.dao.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sayimo.framework.database.mybatis.AbstractMybatisBaseDao;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao;
import com.sayimo.maker.mall.orders.vo.OrdersList;




@Repository(value="ordersListInterfaceDao")
public class OrdersListDaoImpl extends AbstractMybatisBaseDao<OrdersList> implements OrdersListInterfaceDao{

	@Override
	public Integer insertOrderList(OrdersList ordersList) throws DaoException {
		return mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.insertOrderList", ordersList);
	}

	@Override
	public Integer queryOrderByOrdersNoCount(String ordersNo) throws DaoException {
		return mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrderByOrdersNoCount", ordersNo);
	}
	
	/**
	 * @Title: queryMemberCustomerOrderList
	 * @Author: 曹频辉
	 * @Date:日期：2016年1月6日 时间：上午10:50:45
	 * @Description: 根据用户ID查询订单列表
	 * @param customerId
	 * @param status
	 * @throws DaoException
	 * @return List
	 * @Version 1.0.0
	 */
	@Override
	public List queryMemberCustomerOrderList(Integer customerId, Integer status)
			throws DaoException {
		Map map=new HashMap();
		map.put("customerId", customerId);
		map.put("status", status);
		
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getMemberCustomerOrderList", map);
	}
	
	
	/**
	 * @Title: queryMemberCustomerOrderList
	 * @Author: 曹频辉
	 * @Date:日期：2016年1月6日 时间：上午11:20:45
	 * @Description: 根据订单Id查询商品列表
	 * @param ordersId
	 * @throws DaoException
	 * @return List
	 * @Version 1.0.0
	 */
	@Override
	public List getGoodsListByOrdersId(Integer ordersId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getGoodsListByOrdersId", ordersId);
	}

	@Override
	public Integer queryOrdersListTotal(List<Integer> ids) throws DaoException {
		return (Integer) mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersListTotal",ids);
	}
	
	/**
	 * 
	 * @MethodName queryOrdersByBatchCode
	 * @Description 按订单收货地址批次号查询订单信息
	 * 
	 * @author chenpy
	 * @date 2016年1月8日 下午3:57:59
	 * @param 
	 * @return List<OrdersList>
	 * @VERSION 1.0.0
	 */
	public List<OrdersList> queryOrdersByBatchCode(String batchCode) throws DaoException{
		return mybatisInterfaceBaseDao.query("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersByBatchCode", batchCode);
	}

	/**
	 * @Title: batchUpdateOrdersList
	 * @Author: chenpy
	 * @Date:日期：2016年1月8日 时间：下午4:05:03
	 * @Description: 批量修改订单状态
	 * @param list
	 * @throws DaoException
	 * @return Integer
	 * @Version 1.0.0
	 */
	public Integer batchUpdateOrdersList(List<OrdersList> list) throws DaoException{
		return mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.batchUpdateOrdersList", list);
	}

	@Override
	public Map<String, Object> queryOrdersTotalMoneyByIds(List<Integer> ids) throws DaoException {
		return (Map<String, Object>) mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersTotalMoneyByIds", ids);
	}

	@Override
	public void updateOrdertotalAmountById(Integer id) throws DaoException {
		mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateOrdertotalAmountById",id);
	}

	@Override
	public OrdersList queryOrdersListById(Integer id) throws DaoException {
		return mybatisInterfaceBaseDao.get("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersListById", id);
	}

	/**
	 * @Title: updateOrdersList
	 * @Author: chenpy
	 * @Date:日期：2016年1月13日 时间：下午2：07
	 * @Description: 修改订单
	 * @param list
	 * @throws DaoException
	 * @return Integer
	 * @Version 1.0.0
	 */
	public Integer updateOrdersList(OrdersList list) throws DaoException {
		return mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateOrdersList", list);
	}

	@Override
	public Integer updateOrdersListStatus(Map<String, Object> pm) throws DaoException {
		return mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateOrdersListStatus", pm);
	}
	
	
	/**
	 * 
	* @Title: getBatchCodeByCustomerId 
	* @Description: 查询用户订单批次号
	* @param customerId
	* @param status
	* @return
	* @throws DaoException
	* @return List
	* @throws
	 */
	@Override
	public List getBatchCodeByCustomerId(Integer customerId, Integer status)
			throws DaoException {
		Map map=new HashMap();
		map.put("customerId", customerId);
		map.put("status", status);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getBatchCodeByCustomerId", map);
	}
	
	
	/**
	 * 
	* @Title: getOrderListByBatchCode 
	* @Description: 根据批次号查询  该批次下订单列表
	* @param batchCode
	* @return
	* @throws DaoException
	* @return List
	* @throws
	 */
	@Override
	public List getOrderListByBatchCode(String batchCode,Integer status) throws DaoException {
		Map map=new HashMap();
		map.put("batchCode", batchCode);
		map.put("status", status);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrderListByBatchCode", map);
	}

	@Override
	public List<OrdersList> queryOrdersByIds(List<Integer> ids) throws DaoException {
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersByIds", ids);
	}
	
	
	
	/**
	 * 
	* @Title: getOrderListByCustomerId 
	* @Description: 查询用户 订单列表
	* @param customerId
	* @param status
	* @return
	* @throws DaoException
	* @return List
	* @throws
	 */
	@Override
	public List getOrderListByCustomerId(Integer customerId, Integer status, Integer pageSize, Integer pageNow,Integer mallType)
			throws DaoException {
		Map map=new HashMap();
		map.put("customerId", customerId);
		map.put("status", status);
		map.put("pageSize", pageSize);
		map.put("pageNow", pageNow);
		map.put("mallType", mallType);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrderListByCustomerId", map);
	}

	@Override
	public void deleteOrdersListStatus0(Integer customerId) throws DaoException {
		this.mybatisInterfaceBaseDao.delete("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.deleteOrdersListStatus0", customerId);
	}
	/**
	 * 
	* @Title: getGoodsInfoOfReturnGoods 
	* @Description: 获取 退换货商品信 息
	* @param orderId
	* @param goodsId
	* @param goodsNormsValueId
	* @return
	* @throws DaoException
	* @return Map<String,Object>
	* @throws
	 */
	@Override
	public Map<String, Object> getGoodsInfoOfReturnGoods(Integer orderId,
			Integer goodsId, Integer goodsNormsValueId) throws DaoException {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("orderId", orderId);
		map.put("goodsId", goodsId);
		map.put("goodsNormsValueId", goodsNormsValueId);
		return (Map<String, Object>)this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getGoodsInfoOfReturnGoods", map);
	}

	@Override
	public List queryCustomerOrderList(Integer customerId, Integer id,String identifier) throws DaoException {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("customerId", customerId);
		map.put("id",id);
		map.put("identifier",identifier);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrderListByCustomerIdAndGoodsId", map);
	}

	public Integer updateOrderSumMoneyById(Map<String, Object> paramMap) throws DaoException {
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateOrderSumMoneyById", paramMap);
	}

	public BigDecimal orderLogistcsCost(List list) throws DaoException {
		return (BigDecimal) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.orderLogistcsCost", list);
	}
	
	@Override
	public Integer updateStatusByTsh(Map<String, Object> paramMap) throws DaoException {
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateStatusByTsh",paramMap);
	}

	@Override
	public List<Object> getProviderOrderList(Integer providerId, Integer status,Integer pageSize,Integer pageNow) throws DaoException {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("providerId", providerId);
		map.put("status",status);
		map.put("pageSize",pageSize);
		map.put("pageNow",pageNow);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.selectOrdersByProviderId", map);
	}

	@Override
	public String getEmsNameById(Integer emsId) throws DaoException {
	
		return (String) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getEmsNameById", emsId);
	}

	/** 
	* @Title: queryOrdersNormsInfoById 
	* @Description: 
	* @param orderId
	* @return
	* @return List
	* @throws 
	*/
	@Override
	public List queryOrdersNormsInfoById(Integer orderId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrdersNormsInfoById", orderId);
	}

	/** 
	* @Title: updateOrdersById 
	* @Description: 修改订单状态
	* @param paramMap
	* @return
	* @return Object
	* @throws 
	*/
	@Override
	public Object updateOrdersById(Map<String, Object> paramMap)
			throws DaoException {
//		ordersDao.update("com.sayimo.school.mall.dao.ope.OrdersDao.updateOrdersById", paramMap)
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.updateOrdersById", paramMap);
	}

	@Override
	public List<Object> getNewTimestamp(Integer providerId, Integer status) throws DaoException {
		Map map=new HashMap();
		map.put("providerId", providerId);
		map.put("status", status);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getNewTimestamp", map);
	}

	@Override
	public  Map<String, Object> getActivityBuyNumCountByCustomerId(Integer customerId)
			throws DaoException {
		return  (Map<String, Object>)this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getActivityBuyNumCountByCustomerId",customerId);
	}

	
	public Integer getPaidOrder(String ordersNo) throws DaoException {
		return (Integer) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getPaidOrder", ordersNo);
	}
	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 根据订单号获取订单信息
	  * @param 
	  * @throws 
	  * @return OrdersList
	  * @date 2016年9月26日
	  */ 
	public OrdersList getOrdersListByOrdersNo(String ordersNo) throws DaoException{
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrdersListByOrdersNo", ordersNo);
	}

	@Override
	public Integer deleteOrdersListUnPay(Integer ordersId) throws DaoException {
		return this.mybatisInterfaceBaseDao.deleteById("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.deleteOrdersListUnPay", ordersId);
	}
	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 根据订单号查询同批次的所有订单
	  * @param 
	  * @throws 
	  * @return List
	  * @date 2016年9月27日
	  */ 
	public List getOrdersIdsByBatchCode(String ordersNo) throws DaoException{
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrdersIdsByBatchCode", ordersNo);
	}
	/**
	 * @Package com.sayimo.maker.mall.orders.dao.impl
	 * @Author TANXIN
	 * @MethodName:getCustomerSeckillGoodsBuy
	 * @Description:获取会员当天在该活动的当前时间段购买商品总数
	 * @param customerId
	 * @param identifier
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws DaoException
	 * @Date 2016年10月18日,上午10:32:29
	 */
	@Override
	public Integer getCustomerSeckillGoodsBuy(Integer customerId,
			String identifier,Integer seckillTimesId)
			throws DaoException {
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("customerId", customerId);
		paramMap.put("identifier", identifier);
		paramMap.put("seckillTimesId", seckillTimesId);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getCustomerSeckillGoodsBuy", paramMap);
	}
	
	/**
	 * @Package com.sayimo.maker.mall.orders.dao.impl
	 * @Author TANXIN
	 * @MethodName:getCustomerGoodsBuyByPreOrder
	 * @Description:查询会员购买了该活动商品数量
	 * @param customerId
	 * @param goodsId
	 * @param identifier
	 * @param limitType
	 * @return
	 * @throws DaoException
	 * @Date 2016年10月18日,上午10:54:15
	 */
	@Override
	public Integer getCustomerGoodsBuyByOrder(Integer customerId,
			Integer goodsId, String identifier,Integer limitType) throws DaoException {
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("customerId", customerId);
		paramMap.put("goodsId", goodsId);
		paramMap.put("identifier", identifier);
		paramMap.put("limitType", limitType);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getCustomerGoodsBuyByOrder", paramMap);
	}

	/** 
	* @Title: getCustomerGroupGoodsBuy 
	* @Description: 获取会员在该团购活动的当前时间段购买商品总数
	* @param customerId
	* @param identifier
	* @return
	* @return Integer
	* @throws 
	*/
	@Override
	public Integer getCustomerGroupGoodsBuy(Integer customerId,
			String identifier) throws DaoException {
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("customerId", customerId);
		paramMap.put("identifier", identifier);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getCustomerGroupGoodsBuy", paramMap);
	}

	@Override
	public Integer getCustomerCutPriceGoodsBuy(Integer customerId,
			String identifier) throws DaoException {
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("customerId", customerId);
		paramMap.put("identifier", identifier);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getCustomerCutPriceGoodsBuy", paramMap);
	}


	/** 
	* @Title: queryOrderIdsByidentifier 
	* @Description: 根据标识符查询相应的订单id
	* @param identifier
	* @return
	* @return String
	* @throws 
	*/
	@Override
	public String queryOrderIdsByidentifier(String identifier)
			throws DaoException {
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("identifier", identifier);
		return (String) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryOrderIdsByidentifier", paramMap);
	}

	
	/** 
	  * @package com.sayimo.maker.mall.orders.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 查询订单下指定商品待审核退换货数量
	  * @param 
	  * @throws 
	  * @return Integer
	  * @date 2016年10月26日
	  */ 
	public Integer getReturnGoodsNumInOrder(Map<String, Integer> paramMap ) throws DaoException{
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getReturnGoodsNumInOrder", paramMap);
	}

	 /**
	 * @Package com.sayimo.maker.mall.orders.dao.impl
	 * @Author 龚益君
	 * @MethodName:getOrderListByProviderId
	 * @Description:
	 * @param refId
	 * @param status
	 * @param pageSize
	 * @param pageNow
	 * @return
	 * @throws DaoException
	 * @Date 2017年3月2日,下午5:46:01
	 */
	public List getOrderListByProviderId(Integer refId, Integer status,Integer mallType, Integer pageSize, Integer pageNow)
			throws DaoException {
		Map<String,Object> map = new HashMap<>();
		map.put("refId", refId);
		map.put("status",status);
		map.put("pageSize",pageSize);
		map.put("mallType",mallType);
		map.put("pageNow",pageNow);
		return mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.getOrderListByProviderRefId", map);
	}
	/**
	 * 
	 * @MethodName queryIsOrder
	 * @Description 根据支付宝异步返回的订单号和总金额查询是否存在订单 
	 * @author wangyang
	 * @date 2017年3月2日 上午9:22:56
	 * @param 
	 * @return Integer
	 * @throws Exception 
	 */
	@Override
	public Integer queryIsOrder(String out_trade_no, String total_amount)
			throws DaoException {
		Map<String , Object> paramMap = new HashMap<String , Object>();
		paramMap.put("ordersNo", out_trade_no);
		paramMap.put("totalAmount", total_amount);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.orders.dao.OrdersListInterfaceDao.queryIsOrder", paramMap);
	}

}
